﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Documents;
using DiagramDesigner.Common.Controls;
using System.Windows.Interactivity;

namespace Behavior.Link
{
    public class LinkBehavior : Behavior<DesignerItem>
    {
        private DesignerShape _shape;
        private AnchorPointAdorner _adorner;

        protected override void OnAttached()
        {
            base.OnAttached();
            var di = (AssociatedObject as DesignerItem).Content as DesignerItem;
            _shape = di.Content as DesignerShape;
            if (_shape == null) return;
            _adorner = new AnchorPointAdorner(AssociatedObject, _shape.Points);
            AdornerLayer.GetAdornerLayer(AssociatedObject).Add(_adorner);
        }

        protected override void OnDetaching()
        {
            base.OnDetaching();
            if (_adorner == null) return;
            AdornerLayer.GetAdornerLayer(AssociatedObject).Remove(_adorner);
        }
    }
}
